package com.sx.pipeline.ui.register.adapter

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.sx.pipeline.R
import com.sx.pipeline.repos.http.res.UnitTypeVO

/**
 * @Author: YY
 * @Date: 2022/4/23
 * @Description: TODO
 */
class SelectUnitTypeAdapter(data: MutableList<UnitTypeVO>, private val isMultiSelect: Boolean)
    : BaseQuickAdapter<UnitTypeVO, BaseViewHolder>(R.layout.item_select_unit_type, data) {

    var clickId: Int = 0

    override fun convert(holder: BaseViewHolder, item: UnitTypeVO) {
        holder.setText(R.id.tv_unit_type, item.name)

        if (isMultiSelect) {
            if (item.isSelect) {
                holder.setImageResource(R.id.image_select, R.drawable.icon_radio_button_checked)
            } else {
                holder.setImageResource(R.id.image_select, R.drawable.icon_radio_button_dischecked)
            }
        } else {
            // 单选
            if (clickId == holder.layoutPosition) {
                holder.setImageResource(R.id.image_select, R.drawable.icon_radio_button_checked)
            } else {
                holder.setImageResource(R.id.image_select, R.drawable.icon_radio_button_dischecked)
            }
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setSelectClickId(position: Int) {
        this.clickId = position
        notifyDataSetChanged()
    }
}